package caip2022p.rcv6;

import java.io.*;

public class Main {
	//墙面高和宽
    static int N, M;
    //保存颜色分布
    static char[][] G;
    //记录是否贴了砖
    static int[][] vis;
    //最大可能尺寸
    static int msize = 1000;
    //记录对应型号的砖的数量
    //+1是因为数组从1开始计数
    static int[][] ma = new int[(int)'z'+1][msize+1];
    
    //判断能否贴砖
    static boolean ok(int x, int y, char color) {
    	//(x,y)没超出墙面范围
    	//颜色符合要求
    	//(x,y)没有贴过
        return x >= 0 && x < N && y >= 0 && y < M && G[x][y] == color && vis[x][y] == 0;
    }

    //计算砖的尺寸
    static int f(char color, int x, int y) {
        int len = 1;
        while (true) {
            int flag = 0;
            for (int i = x; i < x + len; i++) {
                if (!ok(i, y + len - 1, color)) {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0) {
                for (int i = y; i < y + len; i++) {
                    if (!ok(x + len - 1, i, color)) {
                        flag = 1;
                        break;
                    }
                }
            }
            if (flag == 1) break;
            len++;
        }
        len--;
        for (int i = x; i < x + len; i++) {
            for (int j = y; j < y + len; j++) {
                vis[i][j] = 1;
            }
        }
        return len;
    }

    public static void main(String[] args) throws IOException {
    	//优化输入
    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    	//优化输出
        StringBuilder sb = new StringBuilder();
        
        String[] nm = br.readLine().split(" ");
        N = Integer.parseInt(nm[0]);
        M = Integer.parseInt(nm[1]);
        G = new char[N][M];
        vis = new int[N][M];

        //读取数据
        for (int i = 0; i < N; i++) {
            String line = br.readLine();
            for (int j = 0; j < M; j++) {
                G[i][j] = line.charAt(j);
            }
        }

        //循环墙面每个位置贴砖
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                if (vis[i][j] == 1) continue;
                int size = f(G[i][j], i, j);
                ma[G[i][j]][size] = ma[G[i][j]][size] + 1;
            }
        }

        //计算砖块种类数
        int count = 0;
        for(int i=0;i<ma.length;i++) {
        	for(int j=0;j<ma[i].length;j++) {
        		if(ma[i][j]>0) {
        			count++;
        		}
        	}
        }
        sb.append(count);
        sb.append("\n");
        
        //不用排序，按题意 { 0-9，a-z，A-Z }分段输出
        //ASCII表格顺序 0-9 A-Z a-z
        //颜色0~9输出
        for(int i=(int)'0';i<=(int)'9';i++) {
        	for(int j=0;j<=msize;j++) {
        		if(ma[i][j]!=0)
        			sb.append(String.format("color = %c; size = %d; amount = %d\n",(char)i, j, ma[i][j]));
        	}
        }
        
        //字符A~Z输出
        for(int i=(int)'A';i<=(int)'Z';i++) {
        	for(int j=0;j<=msize;j++) {
        		if(ma[i][j]!=0)
        			sb.append(String.format("color = %c; size = %d; amount = %d\n",(char)i, j, ma[i][j]));
        	}
        }
        
        //字符a~z输出
        for(int i=(int)'a';i<=(int)'z';i++) {
        	for(int j=0;j<=msize;j++) {
        		if(ma[i][j]!=0)
        			sb.append(String.format("color = %c; size = %d; amount = %d\n",(char)i, j, ma[i][j]));
        	}
        }
        
        System.out.print(sb.toString());
    }
}